import java.util.Arrays;

/**
 * 1720. 解码异或后的数组
 * https://leetcode-cn.com/problems/decode-xored-array/
 */
public class Solutions_1720 {
    public static void main(String[] args) {
//        int[] encoded = {1, 2, 3};
//        int first = 1;  // output: {1, 0, 2, 1}

        int[] encoded = {6, 2, 7, 3};
        int first = 4;  // output: {4, 2, 0, 7, 4}

        int[] result = decode(encoded, first);
        System.out.println(Arrays.toString(result));
    }

    public static int[] decode(int[] encoded, int first) {
        int len = encoded.length;
        int[] res = new int[len + 1];
        res[0] = first;

        for (int i = 0; i < len; i++) {
            res[i + 1] = res[i] ^ encoded[i];
        }
        return res;
    }
}
